// 类型13  function
{

// 函数声明
function add(x:number, y:number): string {
    return x + y + 'px';
}
console.log(add(30, 5));

// 函数表达式
// const func = (n1: number, n2: number): string => {
//     return n1 - n2 + '%';
// }

// const func = (n1: number, n2: number): number => n1 - n2;

// 声明函数 - 声明函数
let liuwei: (arg: boolean) => string;

liuwei = (bool): string => {
    let str: string;
    str = bool ? '成功' : '失败';
    return str;
}
// console.log(liuwei(false));
// console.log(func(11, 6));


// 声明一个函数，参数个数不固定，并不是严格要求
// 需求，传入一个字符，和起始的索引，返回截取的结果
function sliceStr(str: string, s: number, e?: number): string {
    return str.slice(s, e)
}

// 函数参数的默认值  +8613577665487
function getTel(val: number, area: string = '+86'): string {
    return area + val;
}
// console.log(getTel(18844557799, '+86'));
console.log(getTel(18844557799));


// console.log(sliceStr('goodstudydf', 4, 6));
// console.log(sliceStr('goodstudydf', 5));

// React.createElement(参数1， 参数2， 参数3...)
function createEle(str: string, attr: object, ...arg: object[]): object {
    return {
        name: str,
        attr: attr,
        ...arg
    }
}

console.log(createEle('span', {id: '10'}, { name: 'a' }, { name: 'del' }));


}